class MessageHandler:
    def __init__(self, mqtt_client):
        self.mqtt_client = mqtt_client
        self.message_handlers = {
            b'command1': self.handle_command1,
            b'command2': self.handle_command2,
            # 可以添加更多的命令和处理函数
        }

    def process_message(self):
        latest_message = self.mqtt_client.get_latest_message()
        if latest_message:
            topic, msg = latest_message
            print(f"Processing message: {msg} from topic: {topic}")
            
            # 根据消息内容调用相应的处理函数
            handler = self.message_handlers.get(msg)
            if handler:
                return handler(topic, msg)
            else:
                print(f"No handler found for message: {msg}")
        return None

    def handle_command1(self, topic, msg):
        print("Handling command1")
        # 在这里添加处理 command1 的具体逻辑
        # 例如：控制某个设备、更新状态等
        return f"Command1 processed: {msg}"

    def handle_command2(self, topic, msg):
        print("Handling command2")
        # 在这里添加处理 command2 的具体逻辑
        # 例如：发送通知、记录日志等
        return f"Command2 processed: {msg}"